﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Shell="http://schemas.microsoft.com/netfx/2009/xaml/presentation"
                    xmlns:Controls="clr-namespace:BillsManager.Views.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/BillsManager.Views;component/Dictionaries/Styles.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type Controls:WindowEx}"
           x:Key="ViewWindowStyle">

        <Setter Property="UseLayoutRounding"
                Value="True" />
        <!--<Setter Property="AllowsTransparency"
                        Value="True" />-->
        <!--<Setter Property="WindowStyle"
                        Value="None" />-->

        <Setter Property="Background"
                Value="{StaticResource ViewBackgroundBrush}" />
        <Setter Property="BorderBrush"
                Value="{StaticResource ViewBorderBrush}" />
        <Setter Property="Foreground"
                Value="{StaticResource ViewForegroundBrush}" />

        <Setter Property="MinHeight"
                Value="38" />

        <Setter Property="Shell:WindowChrome.WindowChrome">
            <Setter.Value>
                <Shell:WindowChrome CornerRadius="{StaticResource ViewCornerRadius}"
                                    ResizeBorderThickness="{StaticResource ResizeBorderThickness}"
                                    NonClientFrameEdges="None"
                                    GlassFrameThickness="0"
                                    CaptionHeight="32" />
            </Setter.Value>
        </Setter>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:WindowEx}">

                    <AdornerDecorator>

                        <Border x:Name="WindowBorder"
                                BorderBrush="{StaticResource ViewBorderBrush}"
                                Background="{StaticResource ViewBackgroundBrush}"
                                BorderThickness="{StaticResource BorderThickness}"
                                Padding="{StaticResource ViewBorderPadding}">

                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="{StaticResource MarginSize}" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <Grid HorizontalAlignment="Stretch">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="{StaticResource MarginSize}" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="{StaticResource MarginSize}" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <!--<Rectangle Fill="Green"
                                                       Grid.ColumnSpan="5" />-->

                                    <Image Stretch="Uniform"
                                           VerticalAlignment="Top"
                                           HorizontalAlignment="Left"
                                           Source="{TemplateBinding Icon}"
                                           Height="{StaticResource ViewIconSize}"
                                           Width="{StaticResource ViewIconSize}">
                                        <Image.Margin>
                                            <Thickness Left="{StaticResource RegionSeparatorSizeValue}"
                                                       Top="{StaticResource RegionSeparatorSizeValue}"
                                                       Right="{StaticResource RegionSeparatorSizeValue}"
                                                       Bottom="{StaticResource RegionSeparatorSizeValue}" />
                                        </Image.Margin>
                                    </Image>

                                    <TextBlock Text="{TemplateBinding Title}"
                                               Foreground="{StaticResource ViewTitleBrush}"
                                               FontSize="{StaticResource ViewTitleFontSize}"
                                               Grid.Column="2"
                                               HorizontalAlignment="Stretch"
                                               VerticalAlignment="Center"
                                               TextAlignment="Center"
                                               TextWrapping="NoWrap"
                                               TextTrimming="CharacterEllipsis" />

                                    <StackPanel Orientation="Horizontal"
                                                x:Name="controlBox"
                                                Grid.Column="4"
                                                VerticalAlignment="Top"
                                                HorizontalAlignment="Right"
                                                Shell:WindowChrome.IsHitTestVisibleInChrome="True">
                                        <Controls:MinimizeWindowButton Visibility="{Binding ShowInTaskbar, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" />
                                        <Controls:NormalizeWindowButton x:Name="NormalizeWindowButton"
                                                                        Visibility="Collapsed" />
                                        <Controls:MaximizeWindowButton x:Name="MaximizeWindowButton" />
                                        <Controls:CloseWindowButton Visibility="{Binding CanClose, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" />
                                    </StackPanel>

                                </Grid>

                                <ContentPresenter Grid.Row="2"
                                                  Content="{TemplateBinding Content}"
                                                  ContentTemplate="{TemplateBinding ContentTemplate}"
                                                  ContentStringFormat="{TemplateBinding ContentStringFormat}" />

                            </Grid>

                        </Border>

                    </AdornerDecorator>

                    <ControlTemplate.Triggers>

                        <Trigger Property="WindowState"
                                 Value="Maximized">
                            <Setter TargetName="NormalizeWindowButton"
                                    Property="Visibility"
                                    Value="Visible" />
                            <Setter TargetName="MaximizeWindowButton"
                                    Property="Visibility"
                                    Value="Collapsed" />
                            <!--<Setter TargetName="controlBox"
                                            Property="Margin"
                                            Value="0 -1 -1 0" />-->
                        </Trigger>

                        <Trigger Property="ResizeMode"
                                 Value="NoResize">
                            <Setter TargetName="NormalizeWindowButton"
                                    Property="Visibility"
                                    Value="Collapsed" />
                            <Setter TargetName="MaximizeWindowButton"
                                    Property="Visibility"
                                    Value="Collapsed" />
                        </Trigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

</ResourceDictionary>